package kGeom;

//TODO: fully impliment this!!
public class kPolyline extends kElement {
	private kPointCloud	points;
	private static float thresh = (Float.MIN_VALUE)*2;
	
	public kPolyline(){
		points = new kPointCloud();
		points.thresh = thresh;
	}
	
	public kPolyline(kVec[] pArr){
		points = new kPointCloud(pArr);
		points.thresh = thresh;
	}
	
	
	/*
	 * FIELDS
	 */
	
	public int countPts(){
		return points.count();
	}
	public int countLns(){
		return points.count()-1;
	}
	public kRange range(){
		return points.getRange();
	}
	

	
	/*
	 * POINT MANAGEMENT METHODS
	 */
	
	public kVec getPointAt(int index) {
		if ((index >= 0) && (index < points.count()  )) return points.getAt(index);
		else {
			System.out.println("!!! kPolyline.getPointAt("+index+") index out of range");
			return new kVec();
		}
	}
	public boolean setPointAt(int index, kVec p) {
		if ((index >= 0) && (index < points.count())) {
			points.setAt(index, p);
			return true;
		} else {
			System.out.println("!!! kPolyline.setPointAt("+index+") index out of range");
			return false;
		}
	}
	
	public int append(kVec pt){
		return points.append(pt);
	}
	
	
	/*
	 * LINE MANAGEMENT METHODS
	 */
	
	public kLine getLineSegment(int index) {
		if ((index >= 0) && (index < points.count()-1 )) {
			return new kLine( points.getAt(index), points.getAt(index+1) );
		} else {
			System.out.println("!!! kPolyline.getLineAt("+index+") index out of range");
			return new kLine();
		}
	}
	public boolean setLineSegment(int index, kLine ln) {
		if ((index >= 0) && (index < points.count()-1 )) {
			points.setAt(index, ln.StartPoint());
			points.setAt(index+1, ln.EndPoint());
			return true;
		} else {
			System.out.println("!!! kPolyline.setLineSegment("+index+") index out of range");
			return false;
		}
	}
	
	
	/*
	 * MANIPULATION
	 */
	
	public void translate(kVec vec){points.translate(vec);}
	public void scale(float s){points.scale(s);}
    public void scaleX(float s){points.scaleX(s);}
    public void scaleY(float s){points.scaleY(s);}
    public void scaleZ(float s){points.scaleZ(s);}
    public void flipAxis(int axisFlip){points = kPointCloud.flipAxis(points, axisFlip);}
    
}
